import React,{Component} from 'react';
import * as pub from '../../config/public';
import * as fetch from '../../config/fetch';
import {Spin,message} from 'antd';
import Pages from '../Pages';
import CourseSmall from '../CourseSmall';

class CourseMore extends Component {
    constructor(props) {
        super(props);
        this.state = {
            myCourseList:[],
            loading : false,
            totalPage : 0 ,
            jumpPage : 1,
            userDetail:{},
        }
    }
    getCharList(){
        pub.loading(this,true);
        fetch.courseMore({pageno:this.state.jumpPage}).then((data) => {
            this.setState({
                myCourseList: data.myCourseList?data.myCourseList:[],
                totalPage:data.totalPage?data.totalPage:0,
                userDetail:data.userDetail?data.userDetail:{}
            });
            pub.loading(this,false);
        },(res)=>{
            pub.loading(this,false);
            pub.reject(res);
        })
    }

     componentWillMount() {
        this.getCharList();
     }
     jump(page) {
         this.setState({
            jumpPage:page, 
         },function(){
             this.getCharList();
         })
     }
     operate(id, type) {
		fetch.operateCourse(id, type).then((data) => {
			if (data.result === 'RC100') {
				this.getCharList();
                message.success(data.errMsg, 3);
			}else{
                message.error(data.errMsg, 3);
            }
		})
	}
    refreshCourse(){
        this.getCharList();
    }
    render(){
        let userDetail=this.state.userDetail;
        return(
                <div className="wrapper bg-F0F4F6">
                        <div className="common-title">
                                        <span>学员信息</span>
                                    </div>
                                    <div className="panel-120 bg-FFFFFF box-shadow">
                                        <div className="pepole-info">
                                            <a>
                                            	<img  src={pub.getFile(userDetail.headPath)} onError={(e) => pub.headImageError(e)} alt='封面图片' />
                                                <p><font>{userDetail.userRealName?userDetail.userRealName:''}</font>{userDetail.branchOffice?userDetail.branchOffice:''}</p>
                                                <p>已通过<span style={{padding: '0 5px'}}>{userDetail.sumPassCouse?userDetail.sumPassCouse:0}</span>门课程</p>
                                            </a>
                                            <p>{userDetail.seifInformation?userDetail.seifInformation:''}</p>
                                        </div>
                                    </div>
                        <div className="layout clearFix pad-t-20">
                        <div className="common-title">
                            <span>课程动态</span>
                        </div>
                        <Spin spinning={this.state.loading} tip="加载列表中...">
                        <div className='courses'>
                        {
                            this.state.myCourseList.map((item,index)=>{
                                return(
                               <div key={index}>
                               		<CourseSmall course={item} show={this.getCharList.bind(this)} userCourseOperation={item.userCourseOperation} refreshCourse={this.refreshCourse.bind(this)} id={item.courseId}/>
                                    </div>
                                )
                            })
                        }
                        </div>
                        </Spin>
                       {/* <div className="line"></div>*/}
                         <Pages totalPage={this.state.totalPage} jump={this.jump.bind(this)}/>
                    </div>
                </div>
            )
    }
}
export default CourseMore;